TOP_DIR=../../../
include $(TOP_DIR)/src/build.conf
include $(TOP_DIR)/src/cross.conf

ARCH := i386

ifeq ("$(ARCH)", "i386")
	export FLAG_M32=-m32
else
	export FLAG_M32=
endif

PREFIX=../../../output/root/
INSTALL_DIR=$(PREFIX)
IMPORT_DIR=../../../3rd_party
#NET_SNMP=net-snmp-5.4.1
SRC_DIR=$(NET_SNMP)
INSTALL=install
#all: snmppacket nvw2500snmp
#all: snmppacket
#PATCH1=../patch/wins.patch
#PATCH2=../patch/index_dir.patch
#PATCH3=../patch/system_descr.patch
#PATCH4=../patch/gethostbyname.patch
#PATCH5=../patch/snmp_version.patch
#PATCH6=../patch/syslog_cons.patch
#PATCH7=../patch/snmpUDPIPv6Domain.patch
#PATCH8=../patch/snmpUDPDomain.patch
#PATCH9=../patch/vmstat.patch
#PATCH10=../patch/interface.patch

all:
	make -C src PREFIX=../$(PREFIX)

#snmppacket:
#	make -C src PREFIX=../$(PREFIX)
#	tar -zxvf $(IMPORT_DIR)/$(NET_SNMP).tar.gz && \
	cd $(SRC_DIR) && ./configure CC=$(CC) --with-sys-location="" \
	--with-logfile="/var/log/snmpd.log" \
	--with-persistent-directory="/var/net-snmp" \
	--sysconfdir="/etc" \
	--with-out-mib-modules="host agentx smux" --with-sys-contact="" \
	--with-default-snmp-version="2" \
	--without-kmem-usage --disable-privacy --enable-internal-md5 \
	--without-openssl --with-mibdirs="/usr/share/snmp/mibs" \
	--disable-debugging \
	--disable-embedded-perl --without-perl-modules <<EOF && \
	make all

#nvw2500snmp:
#	$(CC) src/nvw2500snmp.c -o src/$@ -L../clientinfo/lib -I../clientinfo/include -I../MPolicy -lclientinfo

install:
#	$(INSTALL) -d $(PREFIX)/usr/sbin
#	$(INSTALL) -d $(PREFIX)/usr/lib
#	$(INSTALL) -d $(PREFIX)/etc/init.d
#	$(INSTALL) -d $(PREFIX)/usr/share/snmp/mibs
#	$(STRIP) $(SRC_DIR)/agent/.libs/*.so.*
#	cp -avf $(SRC_DIR)/agent/.libs/*.so* $(PREFIX)/usr/lib/
#	$(STRIP) $(SRC_DIR)/agent/helpers/.libs/*.so.*
#	cp -avf $(SRC_DIR)/agent/helpers/.libs/*.so* $(PREFIX)/usr/lib/
#	$(STRIP) $(SRC_DIR)/snmplib/.libs/*.so.*
#	cp -avf $(SRC_DIR)/snmplib/.libs/*.so* $(PREFIX)/usr/lib/
#	$(INSTALL) -s -m 755 $(SRC_DIR)/agent/.libs/snmpd $(PREFIX)/usr/sbin/
#	$(INSTALL) -s -m 755 $(SRC_DIR)/apps/.libs/snmptrap $(PREFIX)/usr/sbin/
#	$(INSTALL) -m 755 $(SRC_DIR)/mibs/*.txt $(PREFIX)/usr/share/snmp/mibs/
	make -C src/ install PREFIX=../$(PREFIX)
	$(INSTALL) -m 644 TRENDMICRO-*.txt $(PREFIX)/usr/share/snmp/mibs/
	$(INSTALL) -m 644 trendMicro_V2.mib $(PREFIX)/usr/share/snmp/mibs/
	$(INSTALL) -m 755 rcSNMP.sh $(PREFIX)/etc/init.d/
	$(INSTALL) -m 755 sendtrap.sh $(PREFIX)/usr/sbin/
#	$(INSTALL) -m 755 src/nvw2500snmp $(PREFIX)/usr/sbin/
	$(INSTALL) -d $(PREFIX)/etc/snmp
	$(INSTALL) -m 600 snmpd.conf.default $(PREFIX)/etc/snmp/
#	mkdir -p $(PREFIX)/etc/snmp
#	ln -fs /var/conf/snmpd.conf $(PREFIX)/etc/snmp/snmpd.conf
	rm -f $(PREFIX)/usr/share/snmp/mibs/IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt
	rm -fr ../../../output/image/mib.zip mibs
	mkdir mibs
	cp -a $(PREFIX)/usr/share/snmp/mibs/UCD-SNMP-MIB.txt \
		$(PREFIX)/usr/share/snmp/mibs/NET-SNMP-*.txt \
		$(PREFIX)/usr/share/snmp/mibs/INET-ADDRESS-MIB.txt mibs
	cp TRENDMICRO-MIB.txt TRENDMICRO-!!ProductNameTag!!-MIB.txt
	zip -r ../../../output/image/mib.zip mibs \
						trendMicro_V2.mib \
						TRENDMICRO-!!ProductNameTag!!-MIB.txt
	install -d $(PREFIX)/opt/TrendMicro/$(PRJNAME)/www/nonprotect/
	install -m 444 ../../../output/image/mib.zip $(PREFIX)/opt/TrendMicro/$(PRJNAME)/www/nonprotect/

L10N:

clean:
	rm -rf $(SRC_DIR)
	rm -rf mibs
	make -C src/ clean

